/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import com.click.app.Functions;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author ariel
 */
@Entity
@Table(name="salaries")
public class Salary implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Boolean paged;
    private Boolean halfPay;
    private Date initDate;
    private Date endDate;
    private Double amount;
    private Employee employee;
    private List<PaymentsSalary> paymentsSalaries;

    public Salary(){ }

    public Salary(Boolean p, Boolean hP, Date iD, Date eD, Double a, Employee e){
        paged = p;
        halfPay = hP;
        initDate = iD;
        endDate = eD;
        amount = a;
        employee = e;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_salary", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Boolean getPaged() {
        return paged;
    }

    public void setPaged(Boolean paged) {
        this.paged = paged;
    }

    @Column(name = "half_pay")
    public Boolean getHalfPay() {
        return halfPay;
    }

    public void setHalfPay(Boolean halfPay) {
        this.halfPay = halfPay;
    }

    @Column(name = "init_date")
    @Temporal(TemporalType.DATE)
    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }

    @Column(name = "end_date")
    @Temporal(TemporalType.DATE)
    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Double getAmount() {
        return Functions.getDouble3Decimal(amount);
    }

    public void setAmount(Double amount) {
        this.amount = Functions.getDouble3Decimal(amount);
    }

    @JoinColumn(name = "id_employee", referencedColumnName = "id_user")
    @ManyToOne(optional = false)
    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    @OneToMany(mappedBy = "salary")
    public List<PaymentsSalary> getPaymentsSalaries() {
        if (paymentsSalaries==null){
            paymentsSalaries = new ArrayList<PaymentsSalary>();
        }
        return paymentsSalaries;
    }

    public void setPaymentsSalaries(List<PaymentsSalary> paymentsSalaries) {
        this.paymentsSalaries = paymentsSalaries;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Salary)) {
            return false;
        }
        Salary other = (Salary) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.Salary[id=" + id + "]";
    }

}
